﻿package cn.flashk.map.player
{
    import cn.flashk.events.*;
    import cn.flashk.image.*;
    import cn.flashk.net.*;
    import flash.display.*;
    import flash.geom.*;

    public class Player extends Sprite
    {
        protected var abp:AnimationGridBitmap;
        private var hitTestPoints:Array;

        public function Player()
        {
            hitTestPoints = new Array();
            hitTestPoints[0] = new Point();
            hitTestPoints[1] = new Point();
            hitTestPoints[2] = new Point();
            hitTestPoints[3] = new Point();
            abp = new AnimationGridBitmap();
            LoaderManager.getInstance().addEventListener(LoaderManagerEvent.COMPLETE, checkFile);
            LoaderManager.getInstance().load("images/player.png", "player");
            return;
        }// end function

        public function getHittestPoints() : Array
        {
            hitTestPoints[0].x = this.x;
            hitTestPoints[0].y = this.y;
            hitTestPoints[1].x = this.x + this.width;
            hitTestPoints[1].y = this.y;
            hitTestPoints[2].x = this.x;
            hitTestPoints[2].y = this.y + this.height;
            hitTestPoints[3].x = this.x + this.width;
            hitTestPoints[3].y = this.y + this.height;
            return hitTestPoints;
        }// end function

        public function get depthX() : Number
        {
            return this.x;
        }// end function

        public function get depthY() : Number
        {
            return this.y + 60;
        }// end function

        private function checkFile(event:LoaderManagerEvent) : void
        {
            if (event.fileURL == "images/player.png")
            {
                new ImageDecode(event.data, showIt);
            }
            return;
        }// end function

        private function showIt(bitmap:Bitmap) : void
        {
            abp.sourceBitmapData = bitmap.bitmapData.clone();
            abp.setGridSize(66, 63);
            abp.play();
            abp.x = 20;
            abp.scaleX = -1;
            this.addChild(abp);
            return;
        }// end function

    }
}
